<template>
  <div>
    <van-swipe class="my-swipe" :autoplay="2000" indicator-color="#888">
      <van-swipe-item>
        <img src="../../assets/1.png" alt="" />
      </van-swipe-item>
      <van-swipe-item>
        <img src="../../assets/2.png" alt="" />
      </van-swipe-item>
      <van-swipe-item>
        <img src="../../assets/3.png" alt="" />
      </van-swipe-item>
    </van-swipe>
    <header>
      <div class="lef">
        <div class="leftcity">
          <router-link to="/listcity">
            <span ref="city">{{ city || '上海' }}</span>
          </router-link>
          <van-icon name="arrow-down" />
        </div>
        <van-icon class="icon" color="#c7c9ca" name="search" />
        <input type="text" placeholder="请输入小区和地址" />
      </div>
      <div class="rig" @click='map'>
        <van-icon color="#fff" name="map-marked" />
      </div>
    </header>
    <van-grid :border="false">
      <van-grid-item icon="wap-home-o" text="整租" />
      <van-grid-item icon="friends-o" text="合租" />
      <van-grid-item icon="location-o" text="地图找房" />
      <van-grid-item to="/gorent" icon="balance-list-o" text="去出租" />
    </van-grid>
    <div class="groups">
      <van-cell-group>
        <van-cell
          title-style="font-weight: 700;"
          class="topnav"
          title="租房小组"
          value="更多"
        />
      </van-cell-group>
      <van-grid direction="horizontal" :gutter="10" :column-num="2">
        <van-grid-item v-for="item in list" :key="item.id">
          <div class="imgleft">
            <!-- <img :src="item.imgSrc" alt=""> -->
          </div>
          <div class="inforight">
            <span>{{ item.title }}</span>
            <span>{{ item.desc }}</span>
          </div>
        </van-grid-item>
      </van-grid>
    </div>
  </div>
</template>

<script>
import { groups, areaIhfo } from '@/api/article'
import { setCityname, setCitycode, getCityname } from '@/utils/storage'
export default {
  async created() {
    this.city = getCityname()
    const { body } = await groups()
    this.list = body
    // console.log(body)
  },
  mounted() {
    this.getcity()
  },
  data() {
    return {
      city: '',
      list: [],
      value: ''
    }
  },
  methods: {
    async getcity() {
      const {
        body: { label, value }
      } = await areaIhfo(this.$refs.city.innerHTML)
      setCityname(label)
      setCitycode(value)
    },
    map() {
      this.$router.push('/maprent')
    }
  }
}
</script>

<style lang="less" scoped>
.my-swipe .van-swipe-item {
  img {
    width: 100%;
  }
}
header {
  position: fixed;
  top: 1.25rem;
  left: 0.625rem;
  width: 95%;
  display: flex;
  justify-content: space-between;
  .lef {
    display: flex;
    padding: 10px 0;
    width: 90%;
    height: 1.25rem;
    line-height: 1.25rem;
    border-radius: 0.25rem;
    background-color: #fff;
    input {
      border: 0;
    }
    ::placeholder {
      font-size: 0.875rem;
      color: #c7c9ca;
    }
    .icon {
      margin-top: 3px;
    }
    .leftcity {
      margin: 0 0.625rem;
      padding-right: 0.625rem;
      border-right: 1px solid #999;
      a {
        font-size: 0.2rem;
        color: #333;
      }
    }
  }
  .rig {
    margin: 10px;
    text-align: center;
    width: 20px;
    height: 20px;
    line-height: 20px;
    border: 1px solid #fff;
    border-radius: 50%;
  }
}
.groups {
  padding: 0 10px 10px;
  background-color: #f6f5f6;
  .topnav {
    background-color: #f6f5f6;
  }
  .imgleft {
    width: 50px;
    height: 50px;
    img {
      width: 100%;
    }
  }
  .inforight {
    display: flex;
    flex-direction: column;
  }
}
</style>
